<?php

namespace Biz\Transformers\Site;

use Biz\Dictionaries\Paper\PaperStatusDict;
use Biz\Models\User\User;
use Lumen\Http\Resources\Json\Resource;
use Biz\Constants\Site\SitePaperConstants;

/**
 * PaperTransformer.
 *
 * @license [http://www.85do.com] [杭州永奥网络科技有限公司]
 * @copyright Copyright (c) 2018-2026 Hangzhou Yongao Technology Co., Ltd. All rights reserved.
 */
class PaperTransformer extends Resource
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     *
     * @return array
     */
    public function toArray($request)
    {
        /** @var \Biz\Models\User\User $user */
        //$user = $request->user();

        return [
            'uid'                         => $this->uid,
            'number'                      => $this->number,
            'presentation_preference'     => $this->presentation_preference,
            'presentation_preference_name'=> $this->presentation_preference,
            'status'                      => $this->status,
            'status_name'                 => PaperStatusDict::get($this->status),
            'created_at'                  => $this->created_at->getTimestamp(),
            $this->mergeWhen($this->relationLoaded('full'), [
                'full' => $this->getPaperFullTransformer(),
            ]),
            $this->mergeWhen($this->relationLoaded('authors'), [
                'authors' => $this->getPaperAuthorTransformerCollection(),
            ]),
            $this->mergeWhen($this->relationLoaded('abstract'), [
                'abstract' => $this->getPaperAbstractTransformer(),
            ]),
            $this->mergeWhen($this->relationLoaded('translations'), [
                'translation' => $this->getPaperTranslationTransformer(),
            ]),
        ];
    }

//    /**
//     * Get status name.
//     *
//     * @param User $user
//     *
//     * @return string
//     */
//    public function getStatusName(User $user): string
//    {
//        if ($user->isClient()) {
//            return SitePaperConstants::$ClientStatusNames[$this->status];
//        } elseif ($user->isMember()) {
//            return SitePaperConstants::$MemberStatusNames[$this->status];
//        }
//
//        return '';
//    }

    /**
     * Get resource.
     *
     * @return PaperAbstractTransformer|null
     */
    public function getPaperAbstractTransformer()
    {
        if ($this->relationLoaded('abstract')) {
            return new PaperAbstractTransformer($this->abstract);
        }

        return null;
    }

    /**
     * Get resource.
     *
     * @return PaperFullTransformer|null
     */
    public function getPaperFullTransformer()
    {
        if ($this->relationLoaded('full')) {
            return new PaperFullTransformer($this->full);
        }

        return null;
    }

    /**
     * Get app resource.
     *
     * @return PaperAuthorTransformerCollection|null
     */
    public function getPaperAuthorTransformerCollection()
    {
        if ($this->relationLoaded('authors')) {
            return new PaperAuthorTransformerCollection($this->authors);
        }

        return null;
    }

    /**
     * Get app resource.
     *
     * @return PaperTranslationTransformerCollection|null
     */
    public function getPaperTranslationTransformer()
    {
        if ($this->relationLoaded('translations')) {
            return new PaperTranslationTransformer($this->translate());
        }

        return null;
    }
}
